/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package BoardGameLanguage.impl;

import BoardGameLanguage.BoardGameLanguagePackage;
import BoardGameLanguage.Field;
import BoardGameLanguage.Figure;
import BoardGameLanguage.Rook;

import de.upb.tools.sdm.*;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Rook</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * </p>
 *
 * @generated
 */
public abstract class RookImpl extends FigureImpl implements Rook {
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected RookImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return BoardGameLanguagePackage.Literals.ROOK;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void move(Field targetField) {
		boolean fujaba__Success = false;
		Field currentField = null;

		// story pattern bind this and currentField
		try {
			fujaba__Success = false;

			// bind object
			currentField = this.getField();

			// check object currentField is really bound
			JavaSDM.ensure(currentField != null);

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern check row
		try {
			fujaba__Success = false;

			// check object currentField is really bound
			JavaSDM.ensure(currentField != null);
			// check object targetField is really bound
			JavaSDM.ensure(targetField != null);
			// check isomorphic binding between objects targetField and currentField
			JavaSDM.ensure(!targetField.equals(currentField));

			// attribute condition
			JavaSDM.ensure(targetField.getRow() == currentField.getRow());

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		if (fujaba__Success) {
			this.performMove(targetField);

		} else {
			// story pattern check column
			try {
				fujaba__Success = false;

				// check object currentField is really bound
				JavaSDM.ensure(currentField != null);
				// check object targetField is really bound
				JavaSDM.ensure(targetField != null);
				// check isomorphic binding between objects targetField and currentField
				JavaSDM.ensure(!targetField.equals(currentField));

				// attribute condition
				JavaSDM.ensure(targetField.getColumn() == currentField
						.getColumn());

				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			if (fujaba__Success) {
				this.performMove(targetField);

			} else {

			}

		}
		return;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eDerivedOperationID(int baseOperationID, Class<?> baseClass) {
		if (baseClass == Figure.class) {
			switch (baseOperationID) {
			case BoardGameLanguagePackage.FIGURE___MOVE__FIELD:
				return BoardGameLanguagePackage.ROOK___MOVE__FIELD;
			default:
				return super.eDerivedOperationID(baseOperationID, baseClass);
			}
		}
		return super.eDerivedOperationID(baseOperationID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eInvoke(int operationID, EList<?> arguments)
			throws InvocationTargetException {
		switch (operationID) {
		case BoardGameLanguagePackage.ROOK___MOVE__FIELD:
			move((Field) arguments.get(0));
			return null;
		}
		return super.eInvoke(operationID, arguments);
	}

} //RookImpl
